<?php
namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * 基类
 */
class BaseModel extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = 'datetime';

    protected $isPage = true;
    protected $jsonAssoc = true;
    /**
     * 获取某个字段数组
     * @param array $where
     * @param string $field
     * @param string $key
     * @return array
     */
    public function getColumn(array $where, string $field, string $key = '')
    {
        return $this->getModel()->where($where)->column($field, $key);
    }

    public function isPage(){
        return $this->isPage;
    }

    public function searchIdAttr($query, $value, $data)
    {
        $query->whereIn("__TABLE__.id", $value);
    }

    public function searchIsPageAttr($query, $value, $data)
    {
        if ($value == 'false' || $value == '0'|| $value == 0) {
            $this->isPage = false;
        } elseif ($value == 'true') {
            $this->isPage = true;
        }
    }

    public function searchExportAttr($query, $value, $data)
    {
        if (!empty($value)) {
            $this->isPage = false;
        }
    }
}
